package de.uni_mannheim.informatik.ai.dame_ai.dame.ui;

import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;


public class BitmapComponent extends Canvas
{
  protected BufferedImage img;
  protected Rectangle bounds;
  public BitmapComponent(BufferedImage img, Rectangle r)
  {
    this.img = img;
    bounds = r;
    setBounds(r);
  }

  public void paint(Graphics g)
  {
	  System.out.println("image being painted");
	  Graphics2D g2=(Graphics2D)g;
	  g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
	  g2.drawImage(img, 0, 0, bounds.width, bounds.height, this);
  }
  /**
   * Set new Bounds for the component
   * @param r
   */
  public void setNewBounds(Rectangle r){
	  if(!this.getBounds().equals(r)){
		  setBounds(r);
		  bounds = r;
		  System.out.println("BitmapComponent: set new bounds");
		  repaint();
	  }
	  
  }
  public Dimension getPreferredSize()
  {
    return new Dimension(
      img.getWidth(),
      img.getHeight()
    );
  }
  /**
   * Set new image
   * @param img New image
   */
  public void changeImage( BufferedImage img )
  {
    this.img = img;
    this.repaint();
  }
}